  -- Picture4 Sprite
	Pic4Gen : process (clk_25)
  begin
		if rising_edge( clk_25 ) then
			if reset = '1' then -- reset
				is_sprite_show <= '0';
			elsif sprite_status( 20 ) = '1' then -- disable sprite
				is_sprite_show <= '0';
			elsif sprite_status( 4 ) = '0' then -- show back
				if Hcount > HSYNC + HBACK_PORCH + Card_HStart(4) - 1 and Vcount > VSYNC + VBACK_PORCH + Card_VStart(4) - 1 then
					if Hcount < HSYNC + HBACK_PORCH + Card_HStart(4) + 128 and Vcount < VSYNC + VBACK_PORCH + Card_VStart(4) + 64 then
						H4Index <= Hcount - HSYNC - HBACK_PORCH - Card_HStart(4);
						V4Index <= Vcount - VSYNC - VBACK_PORCH - Card_VStart(4);
						H4Boundary <= CardSprite(TO_INTEGER(V4Index));
						if H4Boundary(TO_INTEGER(H4Index)) = '1' then
							is_sprite_show <= '1';
							color_out <= X"AAAA";
						elsif H4Boundary(TO_INTEGER(H4Index)) = '0' then
							is_sprite_show <= '0';
						end if;
					elsif Hcount > HSYNC + HBACK_PORCH + Card_HStart(4) + 127 then
						is_sprite_show <= '0';
					end if; 
				elsif Hcount = HSYNC + HBACK_PORCH + Card_HStart(4) + 127 then
					is_sprite_show <= '0';
				end if;				
			elsif sprite_status( 4 ) = '1' then -- show front
				if Hcount > HSYNC + HBACK_PORCH + Card_HStart(4) - 1 and Vcount > VSYNC + VBACK_PORCH + Card_VStart(4) - 1 then
					if Hcount < HSYNC + HBACK_PORCH + Card_HStart(4) + 128 and Vcount < VSYNC + VBACK_PORCH + Card_VStart(4) + 64 then
						H4Index <= Hcount - HSYNC - HBACK_PORCH - Card_HStart(4);
						V4Index <= Vcount - VSYNC - VBACK_PORCH - Card_VStart(4);
						H4Boundary <= CardSprite(TO_INTEGER(V4Index));
						if H4Boundary(TO_INTEGER(H4Index)) = '1' then
							is_sprite_show <= '1';
							if Hcount = HSYNC + HBACK_PORCH + Card_HStart(4) then
								ram_address <= "000000000000000000" + to_integer( ( Vcount - VSYNC - VBACK_PORCH - Card_VStart( 4 ) ) * 256 );
							else
								ram_address <= ram_address + 2;
							end if;
							color_out <= ram_data;
						elsif H4Boundary(TO_INTEGER(H4Index)) = '0' then
							is_sprite_show <= '0';
						end if;
					elsif Hcount > HSYNC + HBACK_PORCH + Card_HStart(4) + 127 then
						is_sprite_show <= '0';
					end if; 
				elsif Hcount = HSYNC + HBACK_PORCH + Card_HStart(4) + 127 then
					is_sprite_show <= '0';
				end if;
			else
				is_sprite_show <= '0';
			end if;
		end if;
  end process Pic4Gen;
